source Cách tạo Máy tính trong c#

1 using System;
2 using
System.Collections.Generic;
3 using
System.ComponentModel;
4 using
System.Data;
5 using
System.Drawing;
6 using
System.Linq;
7 using
System.Text;
8 using
System.Threading.Tasks;
9 using
System.Windows.Forms;
10 using
System.Text.RegularExpressions;
11 using
NCalc;
12 using
System.IO;
13
14 namespace
Kalkulator
15 {
16     
public partial class Calculator : Form
17     {
18         
public Calculator()
19         {
20             InitializeComponent();
21         }
22
23         
//public string text
24         
//{
25         
// get
26         
// {
27         
// return textBox1.Text;
28         
// }
29         
//}
30
31         
float num1, num2, num3;
32         
//decimal memory = 0;
33         
string memory = "";
34         
//private konv konvForm;
35         
//private MoreForm moreForm;
36
37         
private void button1_Click(object sender, EventArgs e)
38         {
39             textBox1.Text = textBox1.Text +
'0';
40         }
41
42         
private void button5_Click(object sender, EventArgs e)
43         {
44             textBox1.Text = textBox1.Text +
'1';
45         }
46
47         
private void button6_Click(object sender, EventArgs e)
48         {
49             textBox1.Text = textBox1.Text +
'2';
50         }
51
52         
private void button7_Click(object sender, EventArgs e)
53         {
54             textBox1.Text = textBox1.Text +
'3';
55         }
56
57         
private void button9_Click(object sender, EventArgs e)
58         {
59             textBox1.Text = textBox1.Text +
'4';
60         }
61
62         
private void button10_Click(object sender, EventArgs e)
63         {
64             textBox1.Text = textBox1.Text +
'5';
65         }
66
67         
private void button11_Click(object sender, EventArgs e)
68         {
69             textBox1.Text = textBox1.Text +
'6';
70         }
71
72         
private void button13_Click(object sender, EventArgs e)
73         {
74             textBox1.Text = textBox1.Text +
'7';
75         }
76
77         
private void button14_Click(object sender, EventArgs e)
78         {
79             textBox1.Text = textBox1.Text +
'8';
80         }
81
82         
private void button15_Click(object sender, EventArgs e)
83         {
84             textBox1.Text = textBox1.Text +
'9';
85         }
86
87         
private void button2_Click(object sender, EventArgs e)
88         {
89             textBox1.Text = textBox1.Text +
'.';
90             button2.Enabled =
true;
91         }
92
93         
private void button18_Click(object sender, EventArgs e)
94         {
95             textBox1.Text =
"";
96             label1.Text =
"";
97             button18.Enabled =
true;
98         }
99
100         
private void button3_Click(object sender, EventArgs e)
101         {
102             textBox1.Text = textBox1.Text +
'+';
103             button3.Enabled =
true;
104         }
105
106         
private void button8_Click(object sender, EventArgs e)
107         {
108             textBox1.Text = textBox1.Text +
'-';
109             button8.Enabled =
true;
110         }
111
112         
private void button12_Click(object sender, EventArgs e)
113         {
114             textBox1.Text = textBox1.Text +
'*';
115             button12.Enabled =
true;
116         }
117
118         
private void button16_Click(object sender, EventArgs e)
119         {
120             textBox1.Text = textBox1.Text +
'/';
121             button16.Enabled =
true;
122         }
123
124         MathParser.Parser p =
new MathParser.Parser();
125         
private void button4_Click(object sender, EventArgs e)
126         {
127             {
128                 
if (p.Evaluate(textBox1.Text))
129                     Convert.ToDouble(p.Result);
130                 textBox1.Text = p.Result.ToString();
131             }
132             
//if (label1.Text == "+")
133             
//{
134
135             
// num3 = num1 + num2;
136
137             
// textBox1.Text = Convert.ToString(num3);
138             
//}
139
140             
//if (label1.Text == "-")
141             
//{
142             
// num3 = num1 - num2;
143
144             
// textBox1.Text = Convert.ToString(num3);
145             
//}
146
147             
//if (label1.Text == "*")
148             
//{
149             
// num3 = num1 * num2;
150
151             
// textBox1.Text = Convert.ToString(num3);
152             
//}
153
154             
//if (label1.Text == "/")
155             
//{
156             
// num3 = num1 / num2;
157
158             
// textBox1.Text = Convert.ToString(num3);
159             
//}
160             
//if (label1.Text == "%")
161             
//{
162             
// num3 = (num1 / num2) * 100;
163
164             
// textBox1.Text = Convert.ToString(num3);
165             
//}
166
167             
//if (label1.Text == "^")
168             
//{
169             
// double dob = Math.Pow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox1.Text));
170             
// textBox1.Text = "";
171             
// textBox1.Text = dob.ToString();
172             
//}
173             
//if (label1.Text == "%")
174             
//{
175             
// textBox1.Text = mp.Calculate(textBox1.Text).ToString();
176             
//}
177
178             
//if (label1.Text == "MS")
179             
//{
180             
// memory = decimal.Parse(textBox1.Text);
181             
// textBox1.Clear();
182             
//}
183
184             
//if (label1.Text == "M-")
185             
//{
186             
// memory = memory - decimal.Parse(textBox1.Text);
187             
//}
188
189             
//if (label1.Text == "MR")
190             
//{
191             
// textBox1.Text = memory.ToString();
192             
//}
193
194             
//if (label1.Text == "MC")
195             
//{
196             
// memory = 0;
197             
//}
198
199             
//if (label1.Text == "M+")
200             
//{
201             
// memory = memory + decimal.Parse(textBox1.Text);
202
203             
//}
204
205             
//if (label1.Text == "(")
206             
//{
207             
// textBox1.Text = Convert.ToString(num3);
208
209             
//}
210
211             
//if (label1.Text == "(")
212             
//{
213
214             
// textBox1.Text = Convert.ToString(num3);
215             
//}
216
217         }
218
219         
private void button17_Click(object sender, EventArgs e)
220         {
221             
//Faktorijel
222             textBox1.Text = textBox1.Text +
"!";
223             
//int n, s = 1;
224             
//n = Convert.ToInt32(textBox1.Text);
225             
//if (n == 0)
226             
//{
227             
// label1.Text = s.ToString();
228             
//}
229             
//else
230             
//{
231             
// for (int i = 1; i <= n; i++)
232             
// {
233             
// s = s * i;
234             
// label1.Text = s.ToString();
235             
// }
236             
//}
237         }
238
239         
private void Form1_Load(object sender, EventArgs e)
240         {
241
242         }
243
244         
private void button19_Click(object sender, EventArgs e)
245         {
246             textBox1.Text = textBox1.Text +
"sqrt";
247         }
248
249         
private void button20_Click(object sender, EventArgs e)
250         {
251             
if (textBox1.Text.Contains("-"))
252             {
253                 textBox1.Text = textBox1.Text.Remove(
0, 1);
254             }
255             
else
256             {
257                 textBox1.Text =
"-" + textBox1.Text;
258             }
259         }
260
261         
private void button21_Click(object sender, EventArgs e)
262         {
263             textBox1.Text = Convert.ToString((Convert.ToDecimal(textBox1.Text) * Convert.ToDecimal(textBox1.Text)));
264         }
265
266         
private void button22_Click(object sender, EventArgs e)
267         {
268             textBox1.Text = Convert.ToString(((Convert.ToDecimal(textBox1.Text) * Convert.ToDecimal(textBox1.Text) * Convert.ToDecimal(textBox1.Text))));
269         }
270
271         
private void button23_Click(object sender, EventArgs e)
272         {
273             memory = textBox1.Text;
274             label1.Text =
"M+";
275         }
276
277         
private void button24_Click(object sender, EventArgs e)
278         {
279             memory =
"";
280             label1.Text =
"MC";
281         }
282
283         
private void button25_Click(object sender, EventArgs e)
284         {
285             textBox1.Text = memory;
286             label1.Text =
"MR";
287         }
288
289         
private void button26_Click(object sender, EventArgs e)
290         {
291             textBox1.Text = textBox1.Text +
"%";
292         }
293
294         
private void button27_Click(object sender, EventArgs e)
295         {
296             
//textBox1.Text = Convert.ToString(Math.Log10(Convert.ToDouble(textBox1.Text)));
297             textBox1.Text = textBox1.Text +
"log";
298         }
299
300         
private void button28_Click(object sender, EventArgs e)
301         {
302             
//textBox1.Text += button28.Text;
303             
//label1.Text = "(";
304             textBox1.Text = textBox1.Text +
'(';
305         }
306
307         
private void button29_Click(object sender, EventArgs e)
308         {
309             
//textBox1.Text += button29.Text;
310             
//label1.Text = ")";
311             textBox1.Text = textBox1.Text +
')';
312         }
313
314         
private void button30_Click(object sender, EventArgs e)
315         {
316             
//double pi = Math.PI;
317             
//textBox1.Text = Convert.ToString(pi);
318             textBox1.Text = textBox1.Text +
"Pi";
319         }
320
321         
private void button31_Click(object sender, EventArgs e)
322         {
323             
//textBox1.Text = (Math.Sin(Convert.ToDouble(textBox1.Text))).ToString();
324             textBox1.Text = textBox1.Text +
"sin";
325         }
326
327         
private void button34_Click(object sender, EventArgs e)
328         {
329             textBox1.Text = ((
1 / Convert.ToDouble(textBox1.Text))).ToString();
330         }
331
332         
private void button32_Click(object sender, EventArgs e)
333         {
334             
//textBox1.Text = (Math.Cos(Convert.ToDouble(textBox1.Text))).ToString();
335             textBox1.Text = textBox1.Text +
"cos";
336         }
337
338         
private void button33_Click(object sender, EventArgs e)
339         {
340             
//textBox1.Text = (Math.Tan(Convert.ToDouble(textBox1.Text))).ToString();
341             textBox1.Text = textBox1.Text +
"tan";
342         }
343
344         
private void button35_Click(object sender, EventArgs e)
345         {
346             
//double dob = Math.Pow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(label1.Text));
347             
//textBox1.Text = "";
348             
//textBox1.Text = dob.ToString();
349             
//label1.Text = "^";
350             
//num1 = float.Parse(textBox1.Text);
351             
//textBox1.Text = "";
352             
//button35.Enabled = true;
353             textBox1.Text = textBox1.Text +
"^";
354         }
355
356         
private void button36_Click(object sender, EventArgs e)
357         {
358             
if (textBox1.Text.Length > 0)
359             {
360                 textBox1.Text = textBox1.Text.Remove(textBox1.Text.Length -
1, 1);
361             }
362         }
363
364         
private void button37_Click(object sender, EventArgs e)
365         {
366             
//textBox1.Text = (Math.Log(Convert.ToDouble(textBox1.Text))).ToString();
367             textBox1.Text = textBox1.Text +
"ln";
368         }
369
370         
//private void button38_Click(object sender, EventArgs e)
371         
//{
372         
// double dob = Math.Pow(Convert.ToDouble(textBox1.Text), Convert.ToDouble(textBox1.Text));
373         
// textBox1.Text = "";
374         
// textBox1.Text = dob.ToString();
375         
//}
376
377         
private void button38_Click_1(object sender, EventArgs e)
378         {
379             
//textBox1.Text = (Math.Cosh(Convert.ToDouble(textBox1.Text))).ToString();
380             textBox1.Text = textBox1.Text +
"cosh";
381         }
382
383         
private void button39_Click(object sender, EventArgs e)
384         {
385             
//textBox1.Text = (Math.Sinh(Convert.ToDouble(textBox1.Text))).ToString();
386             textBox1.Text = textBox1.Text +
"sinh";
387         }
388
389         
private void button40_Click(object sender, EventArgs e)
390         {
391             
//textBox1.Text = (Math.Tanh(Convert.ToDouble(textBox1.Text))).ToString();
392             textBox1.Text = textBox1.Text +
"tanh";
393         }
394
395         
private void button41_Click(object sender, EventArgs e)
396         {
397             textBox1.Text = (Math.Round(Convert.ToDouble(textBox1.Text))).ToString();
398         }
399
400         
private void button44_Click(object sender, EventArgs e)
401         {
402             
//textBox1.Text = (Math.Asin(Convert.ToDouble(textBox1.Text))).ToString();
403             textBox1.Text = textBox1.Text +
"asin";
404         }
405
406         
private void button45_Click(object sender, EventArgs e)
407         {
408             
//textBox1.Text = (Math.Acos(Convert.ToDouble(textBox1.Text))).ToString();
409             textBox1.Text = textBox1.Text +
"acos";
410         }
411
412         
private void button46_Click(object sender, EventArgs e)
413         {
414             
//textBox1.Text = (Math.Atan(Convert.ToDouble(textBox1.Text))).ToString();
415             textBox1.Text = textBox1.Text +
"atan";
416         }
417
418         
//private void button47_Click(object sender, EventArgs e)
419         
//{
420         
// textBox1.Text = (Math.Floor(Convert.ToDouble(textBox1.Text))).ToString();
421         
//}
422
423         
//private void button48_Click(object sender, EventArgs e)
424         
//{
425         
// textBox1.Text = (Math.Ceiling(Convert.ToDouble(textBox1.Text))).ToString();
426         
//}
427
428         
private void button49_Click(object sender, EventArgs e)
429         {
430             
//textBox1.Text = (Math.Abs(Convert.ToDouble(textBox1.Text))).ToString();
431             textBox1.Text = textBox1.Text +
"abs";
432         }
433
434         
private void button51_Click(object sender, EventArgs e)
435         {
436             
//textBox1.Text = (Math.Exp(Convert.ToDouble(textBox1.Text))).ToString();
437             textBox1.Text = textBox1.Text +
"exp";
438         }
439
440         
private void button50_Click(object sender, EventArgs e)
441         {
442             textBox1.Text = textBox1.Text +
"0.25";
443         }
444
445         
private void button52_Click(object sender, EventArgs e)
446         {
447             textBox1.Text = textBox1.Text +
"0.5";
448         }
449
450         
private void button54_Click(object sender, EventArgs e)
451         {
452             textBox1.Text = textBox1.Text +
"0.75";
453         }
454
455         
private void button53_Click(object sender, EventArgs e)
456         {
457             textBox1.Text = textBox1.Text +
"0.000000000066742";
458         }
459
460         
private void button55_Click(object sender, EventArgs e)
461         {
462             textBox1.Text = textBox1.Text +
"1.324717957244746";
463         }
464
465         
private void button56_Click(object sender, EventArgs e)
466         {
467             textBox1.Text = textBox1.Text +
"2.7182818284590452";
468         }
469
470         
private void button57_Click(object sender, EventArgs e)
471         {
472             textBox1.Text = textBox1.Text +
"1.618033988749894";
473         }
474
475         
private void button42_Click(object sender, EventArgs e)
476         {
477             konv frm2 =
new konv();
478             frm2.frm1 =
this;
479             frm2.ShowDialog();
480         }
481
482         
private void button43_Click(object sender, EventArgs e)
483         {
484             financ fin =
new financ();
485             fin.ShowDialog();
486         }
487
488         
private void button47_Click(object sender, EventArgs e)
489         {
490             formula formul =
new formula();
491             formul.ShowDialog();
492         }
493
494         
private void Calculator_FormClosed(object sender, FormClosedEventArgs e)
495         {
496             Application.Exit();
497         }
498
499         
private void button48_Click(object sender, EventArgs e)
500         {
501             textBox1.Text = textBox1.Text +
"ceil";
502         }
503
504         
private void button53_Click_1(object sender, EventArgs e)
505         {
506             textBox1.Text = textBox1.Text +
"floor";
507         }
508
509         
private void button55_Click_1(object sender, EventArgs e)
510         {
511             textBox1.Text = textBox1.Text +
"sign";
512         }
513         
514         
private void button58_Click(object sender, EventArgs e)
515         {
516             p.Mode = MathParser.Mode.RAD;
517             label1.Text =
"RAD";
518             
519         }
520
521         
void button58_Click2(object sender, EventArgs e)
522         {
523             
524             p.Mode = MathParser.Mode.DEG;
525             label1.Text =
"DEG";
526
527         }
528
529         
void button58_Click3(object sender, EventArgs e)
530         {
531
532             p.Mode = MathParser.Mode.GRAD;
533             label1.Text =
"GRAD";
534
535         }
536         
void button58_Click4(object sender, EventArgs e)
537         {
538
539             p.Mode = MathParser.Mode.RAD;
540             label1.Text =
"RAD";
541
542         }
543
544         
private void button59_Click(object sender, EventArgs e)
545         {
546             p.Mode = MathParser.Mode.DEG;
547             label1.Text =
"DEG";
548         }
549
550         
private void button60_Click(object sender, EventArgs e)
551         {
552             p.Mode = MathParser.Mode.GRAD;
553             label1.Text =
"GRAD";
554         }
555
556     }
557 }


Gõ tìm kiếm nhanh...